package freshmanspecial.mredrock.com.welcomefreshman.Model;

import freshmanspecial.mredrock.com.welcomefreshman.Bean.BeautyInCQUPTBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.ExcellentStuBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.ExcellentTechBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingVideoBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.NatureCQUPTBean;
import freshmanspecial.mredrock.com.welcomefreshman.Service.MienService;
import freshmanspecial.mredrock.com.welcomefreshman.Service.TrainService;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/8/12 0012.
 */

public class MienModel implements IMienModel{

    private String api = "http://yangruixin.com/";

    @Override
    public void getNature(final OnGetMien onGetMien) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(api)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        MienService service = retrofit.create(MienService.class);
        service.getNature("natureCQUPT").
                subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NatureCQUPTBean>() {
                    NatureCQUPTBean bean = null;
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NatureCQUPTBean value) {
                        bean = value;
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete()
                    {
                        if(bean != null) onGetMien.onFinish(bean);
                    }
                });
    }

    @Override
    public void getBeauty(final OnGetMien onGetMien) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(api)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        MienService service = retrofit.create(MienService.class);
        service.getBeauty("beautyInCQUPT").
                subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BeautyInCQUPTBean>() {
                    BeautyInCQUPTBean bean = null;
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BeautyInCQUPTBean value) {
                        bean = value;
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete()
                    {
                        if(bean != null) onGetMien.onFinish(bean);
                    }
                });
    }

    @Override
    public void getTeacher(final OnGetMien onGetMien) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(api)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        MienService service = retrofit.create(MienService.class);
        service.getTeacher("excellentTech").
                subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ExcellentTechBean>() {
                    ExcellentTechBean bean = null;
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ExcellentTechBean value) {
                        bean = value;
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete()
                    {
                        if(bean != null) onGetMien.onFinish(bean);
                    }
                });
    }

    @Override
    public void getStudent(final OnGetMien onGetMien) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(api)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        MienService service = retrofit.create(MienService.class);
        service.getStudent("excellentStu").
                subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ExcellentStuBean>() {
                    ExcellentStuBean bean = null;
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ExcellentStuBean value) {
                        bean = value;
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete()
                    {
                        if(bean != null) onGetMien.onFinish(bean);
                    }
                });
    }

    public interface OnGetMien{
        void onFinish(Object dataBean);
    }
}
